<?php
$sel = JRequest :: getVar("alpha", "ab", "get");
$w = "";
$c = strlen($sel);
for($i = 0; $i < $c; $i++) {
	$w .= "surname LIKE '" . $sel[$i] . "%'";
	$w .= ($i != $c - 1 ? " OR " : "");
}
?>
WHERE confirmed=1 AND (<?php echo $w ?>) ORDER BY surname, name